package com.wgh.common.vo;

import com.wgh.common.constant.Constants;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页结果类
 * 
 * @author AI Shop
 */
@Data
public class PageResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 当前页码
     */
    private Integer pageNum = Constants.DEFAULT_PAGE_NUM;

    /**
     * 每页数量
     */
    private Integer pageSize = Constants.DEFAULT_PAGE_SIZE;

    /**
     * 总记录数
     */
    private Long total;

    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 结果列表
     */
    private List<T> list;

    /**
     * 构造函数
     */
    public PageResult() {
    }

    /**
     * 构造函数
     */
    public PageResult(Integer pageNum, Integer pageSize, Long total, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
        this.totalPage = (int) Math.ceil((double) total / pageSize);
    }

    /**
     * 构造函数
     */
    public PageResult(Integer pageNum, Integer pageSize, Long total, Integer totalPage, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.totalPage = totalPage;
        this.list = list;
    }

    /**
     * 判断是否有下一页
     */
    public boolean hasNextPage() {
        return pageNum < totalPage;
    }

    /**
     * 判断是否有上一页
     */
    public boolean hasPreviousPage() {
        return pageNum > 1;
    }
}